package role

import (
	"context"
	"fast-boot/app/api/admin/internal/svc"
	"fast-boot/app/api/admin/internal/types"
	"fast-boot/app/model"
	"github.com/zeromicro/go-zero/core/logx"
)

type OptionsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 角色下拉列表
func NewOptionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OptionsLogic {
	return &OptionsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *OptionsLogic) Options() (resp []*types.SysRoleOption, err error) {
	roleModel := model.SysRoleModel{}

	var list []*types.SysRoleOption

	l.svcCtx.GormClient.GormDb.Model(roleModel).
		Select("id as value", "name as label ").
		Where("status = 1").
		Order("sort asc, id asc ").
		Scan(&list)

	return list, nil
}
